<?php
/**
 * Easthv Zend Framework Project
 *
 *
 * LICENSE:
 *
 * @category   Zend
 * @package    Zend_Easthv
 * @copyright  Copyright (c) 2009-2010 Easthv Team @ East Hui Van Business Consulting Co., Ltd.(http://www.easthv.com)
 * @license    http://framework.zend.com/license/   BSD License
 * @version    1.0
 * @link       http://www.easthv.com
 * @since      1.0
*/

/**
 * DateTime class
 *
 * @category   Zend
 * @package    Zend_Easthv
 * @copyright  Copyright (c) 2009-2010 Easthv Team @ East Hui Van Business Consulting Co., Ltd.(http://www.easthv.com)
 * @license    http://framework.zend.com/license/   BSD License
 * @version    1.0
 * @link       http://www.easthv.com
 * @since      1.0
 * @deprecated
 */
class Zend_Easthv_System
{

    /**
     * Set System Session (called by model)
     *
     * @param string $key   session name to be set
     * @param mixed $value   session value
     * @param boolean  $encode if true, content will be base64 encoded
     *
     * @access public
     *
     * @return boolean set cookie result
     */
    public static function setSession($key, $value, $encode = false)
    {
        
        $session = new Zend_Session_Namespace('Easthv');

        $session->$key = $encode === false ? $value : base64_encode(serialize($value));

    }
    
    /**
     * Get System session
     *
     * @param string $key   session name to be get
     * @param boolean $encode whether decode session value
     *
     * @access public
     *
     * @return array session array
     */
    public static function getSession($key = null, $decode = false)
    {
        $session = new Zend_Session_Namespace('Easthv');

        return $key ? ($decode === false ? $session->$key : unserialize(base64_decode($session->$key))) : $session;
    }
	

	public static function getLanguage()
	{
		$lang = Zend_Registry::get('lang');
		return $lang ? $lang : 'en';
	}

	public static function getUserScreenNameByUserArray($userArray)
	{

		$username = $userArray['userName'] ? $userArray['userName'] : $userArray['user_name'];
		if(!$username){
			return '';
		}

		if($userArray['Profiles']){
			if($userArray['Profiles']['firstName'] && $userArray['Profiles']['lastName']){
				if(self::getLanguage() == 'zh_CN'){
					$username = $userArray['Profiles']['lastName'] . $userArray['Profiles']['firstName'];
				} else {
					$username =  $userArray['Profiles']['firstName'] . ' ' . $userArray['Profiles']['lastName'];
				}
			}
		}

		return $username;
	}

	public static function getFullUrl($url = null)
	{
		$config = Zend_Registry::get('config');
		
		$base = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://') 
                . ($config['system']['domain']['main']['name'])
				. ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] == 443  ? '' : ':'.$_SERVER['SERVER_PORT']);

		return $base . $url;

	}

	public static function getCaptcha($theme = 'white',$lang = 'en')
	{
		$config = Zend_Registry::get('config');
		if(!$config['system']['3rd']['captcha']['enable']){
			return false;
		}

		$pubKey = $config['system']['3rd']['captcha']['pubKey'];
		$privKey = $config['system']['3rd']['captcha']['privKey'];
		return $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey,null,array(
			'theme' => $theme,
			'lang' => $lang
		));
	}

}
